package com.bone.payment.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.bone.com.service.ComLogService;
import com.bone.payment.dao.PayGatewayDAO;
import com.bone.payment.dao.PayPaymentDAO;
import com.bone.payment.po.PayGateway;
import com.bone.payment.po.PayPayment;
import com.bone.payment.service.PaymentService;

public class PaymentServiceImpl implements PaymentService{
	
	private PayPaymentDAO payPaymentDAO;
	
	private PayGatewayDAO payGatewayDAO;
	
	private ComLogService comLogService;
	
	/**
	 *  保存/修改支付记录.
	 * @param payment
	 * @param operatorId
	 * @return
	 */
	@Override
	public boolean saveOrUpdatePayment(PayPayment payment,String operatorId){
		boolean isSuccess = false;
		String type ="";
		if(payment.getPaymentId()!=null && payment.getPaymentId() > 0){
			isSuccess = payPaymentDAO.updatePayment(payment);
			type = "UPDATE";
		}else{
			isSuccess = payPaymentDAO.insertPayment(payment);
			type = "SAVE";
		}
		if("SAVE".equals(type)){
			comLogService.insertComlog("PAY_PAYMENT", payment.getPaymentId(), operatorId,"SAVE", "添加支付记录","添加支付记录","");
		}if("UPDATE".equals(type)){
			comLogService.insertComlog("PAY_PAYMENT", payment.getPaymentId(), operatorId,"UPDATE", "更新支付记录","更新支付记录","");
		}
		return isSuccess;
	}
	
	/**
	 * 取符合查询条件的标题个数.
	 * @param para
	 * @return
	 */
	@Override
	public Long queryPaymentCountByParam(Map<String, Object> para){
		return this.payPaymentDAO.queryPaymentCountByParam(para);
	}
	/**
	 * 取符合查询条件的标题数据.
	 * @param para
	 * @return
	 */
	@Override
	public List<PayPayment> queryPaymentPageByParam(Map<String, Object> para){
		return this.payPaymentDAO.queryPaymentPageByParam(para);
	}
	 
	/**
	 * 取符合查询条件的标题数据.
	 * @param para
	 * @return
	 */
	@Override
	public List<PayPayment> queryPaymentListByParam(PayPayment payment) {
		return this.payPaymentDAO.queryPaymentListByParam(payment);
	}
	
	/**
	 * 根据对象NO支付交易记录.
	 * @param parameter
	 * @return
	 */
	@Override
	public List<PayPayment> queryPaymentListByObjectNo(Long objectNo) {
		return this.payPaymentDAO.queryPaymentListByObjectNo(objectNo);
	}
	

	//-------------------------------------------------------------------------
	/**
	 *  保存/修改网关记录.
	 * @param payment
	 * @param operatorId
	 * @return
	 */
	@Override
	public boolean saveOrUpdateGateway(PayGateway gateway,String operatorId){
		boolean isSuccess = false;
		String type ="";
		if(gateway.getGatewayId()!=null && gateway.getGatewayId() > 0){
			isSuccess = payGatewayDAO.updateGateway(gateway);
			type = "UPDATE";
		}else{
			gateway.setCreateTime(new Date());
			gateway.setOperator(operatorId);
			isSuccess = payGatewayDAO.insertGateway(gateway);
			type = "SAVE";
		}
		if("SAVE".equals(type)){
			comLogService.insertComlog("PAY_GATEWAY", gateway.getGatewayId(), operatorId,"SAVE", "添加网关记录","添加网关记录","");
		}if("UPDATE".equals(type)){
			comLogService.insertComlog("PAY_GATEWAY", gateway.getGatewayId(), operatorId,"UPDATE", "更新网关记录","更新网关记录","");
		}
		return isSuccess;
	}
	
	/**
	 * 取符合查询条件的网关记录个数.
	 * @param para
	 * @return
	 */
	@Override
	public Long queryGatewayCountByParam(Map<String, Object> para){
		return this.payGatewayDAO.queryGatewayCountByParam(para);
	}

	/**
	 * 取符合查询条件的网关记录数据.
	 * @param para
	 * @return
	 */
	@Override
	public List<PayPayment> queryGatewayPageByParam(Map<String, Object> para){
		return this.payGatewayDAO.queryGatewayPageByParam(para);
	}

	/**
	 * 取符合查询条件的网关记录数据.
	 * @param para
	 * @return
	 */
	@Override
	public List<PayPayment> queryGatewayListByParam(Map<String, Object> para){
		return this.payGatewayDAO.queryGatewayListByParam(para);
	}
	

	/**
	 * 根据网关ID取网关信息.
	 * @param gatewayId
	 * @return
	 */
	@Override
	public PayGateway queryGatewayById(Long gatewayId){
		return payGatewayDAO.queryGatewayById(gatewayId);
	}
	
	
	
	
	public PayPaymentDAO getPayPaymentDAO() {
		return payPaymentDAO;
	}
	public void setPayPaymentDAO(PayPaymentDAO payPaymentDAO) {
		this.payPaymentDAO = payPaymentDAO;
	}
	public PayGatewayDAO getPayGatewayDAO() {
		return payGatewayDAO;
	}
	public void setPayGatewayDAO(PayGatewayDAO payGatewayDAO) {
		this.payGatewayDAO = payGatewayDAO;
	}
	public ComLogService getComLogService() {
		return comLogService;
	}
	public void setComLogService(ComLogService comLogService) {
		this.comLogService = comLogService;
	}
	
}
